const chalk = require('chalk');
const ip = require('ip');
const divider = chalk.gray('\n-----------------------------------');
// const os = require('os');
// let iptable = {};
// let ifaces = os.networkInterfaces();
// for (var dev in ifaces) {
//   ifaces[dev].forEach(function (details, alias) {
//     if (details.family == 'IPv4') {
//       iptable[dev + (alias ? ':' + alias : '')] = details.address;
//     }
//   });
// }
// console.log(iptable);

const logger = {
  error: (err) => {
    console.error(chalk.red(err));
  },

  // 应用启动时触发
  appStarted: (port, host, addStr) => {
    console.log(`Server started ! ${chalk.green('✓')}\n${addStr}`);

    console.log(`
${chalk.bold('Access URLs:')}${divider}
Localhost: ${chalk.magenta(`http://${host}:${port}`)}
      LAN: ${chalk.magenta(`http://${ip.address()}:${port}`)}${divider}
${chalk.blue(`Press ${chalk.italic('CTRL-C')} to stop`)}
    `);
  },
};

module.exports = logger;
